﻿using System.ComponentModel;
using AMatysiak.Converters;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Windows.Forms;

namespace AMatysiakTest.Converters
{
    [TestClass]
    public class DescriptionEnumConverterTest
    {
        enum MyType
        {
            [System.ComponentModel.Description("Type #1")]
            Type1,
            [System.ComponentModel.Description("Type #2")]
            Type2
        }

        private class Money
        {
            private MyType type;
            [TypeConverter(typeof(DescriptionEnumConverter))]
            public MyType Type
            {
                get { return type; }
                set { type = value; }
            }
        }

        [TestMethod]
        public void TestConverter()
        {
            Money money = new Money();
            money.Type = MyType.Type1;

            PropertyGrid grid = new PropertyGrid();
            grid.SelectedObject = money;
            GridItem item = grid.SelectedGridItem;
            PropertyDescriptor pd = item.PropertyDescriptor;
            TypeConverter conv = pd.Converter;
            string type = conv.ConvertTo(money.Type, typeof(string)).ToString();

            Assert.AreEqual("Type #1", type);
        }
    }
}